from gen import generate_test_case
 
def longest_nice_substring(s):
    """
    找到给定字符串中最长的“美好子字符串”。
    一个字符串是“美好的”，如果它包含所有出现的大写字母，
    也包含相应的小写字母，反之亦然。
    """
    if not s:
        return ""

    for i in range(len(s)):
        for j in range(i + 1, len(s) + 1):
            sub = s[i:j]
            is_nice = True
            for char in sub:
                if 'a' <= char <= 'z':
                    if char.upper() not in sub:
                        is_nice = False
                        break
                elif 'A' <= char <= 'Z':
                    if char.lower() not in sub:
                        is_nice = False
                        break
            if is_nice:
                yield sub


def find_longest_nice_substring(s):
    """
    找到字符串中最长的美好子字符串。
    """
    longest = ""
    for sub in longest_nice_substring(s):
        if len(sub) > len(longest):
            longest = sub
    return longest

if __name__ == '__main__':
    # 生成测试用例
    generated_string = generate_test_case()
    
    # 找到最长的美好子字符串
    result = find_longest_nice_substring(generated_string)
 
    # 输出结果
    print(f"Generated string: {generated_string}")
    print(f"Longest nice substring: {result}")